package com.simen.connectandroid.command.pc;

import com.simen.connectandroid.command.PCCommand;
import com.simen.connectandroid.command.utils.CommandCreator;
import com.simen.hellobytes.runtime.RuntimeHelper;

import java.awt.*;
import java.io.File;
import java.io.IOException;

/**
 * 打开指定目
 * <p>
 * Created on 2021/11/19 13:41.
 *
 * @author Simen
 */
public class OpenDirCommand extends PCCommand<OpenDirCommand> {

    private String directory;
    private int processCode;

    public OpenDirCommand() {
    }

    public OpenDirCommand(String directory) {
        this.directory = directory;
    }

    @Override
    public OpenDirCommand exec() {
        try {
            Desktop.getDesktop().open(new File(directory == null ? "." : directory));
        } catch (IOException e) {
            processCode = -1;
            log=e.toString();
        }

        return this;
    }

    @Override
    public boolean execResult() {
        return processCode == 0;
    }

}
